<template>
  <div v-loading="loading">
    <a-form-model
      ref="ruleForm"
      :model="formData"
      :rules="rules"
    >
      <a-row>
        <a-col :span="8">
          <a-form-model-item label="自检人">
            <BaseInput
              v-model="formData.receiverName"
              disabled
            />
          </a-form-model-item>
        </a-col>
        <a-col :span="8">
          <a-form-model-item
            label="自检时间"
            prop="selfCheckDate"
          >
            <a-date-picker
              v-model="formData.selfCheckDate"
              value-format="YYYY-MM-DD"
              :disabled="!editable"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <a-form-model-item
            label="处理情况和自检结果"
            prop="selfCheckResult"
          >
            <BaseTextarea
              v-model="formData.selfCheckResult"
              :disabled="!editable"
              :auto-size="{ minRows: 3, maxRows: 5 }"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
      <a-row>
        <a-col>
          <a-form-model-item
            label="整改照片"
            prop="fileList"
          >
            <l-table
              :disabled="!editable"
              :upload-arrys="formData.fileInfo"
              business-code="MM16"
              upload-type="image"
              count="12"
              edit-model="2"
            />
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
  </div>
</template>
<script>
import { rectificationResultEdit } from '@/api/material/check/rectification'

export default {
	name:'a'+Date.now(),
    props: {
        editable: {
            type: Boolean
        },
        row: {
            type: Object
        }
    },
    data() {
        return {
            loading: false,
            isSubmit: false,
            formData: {
                receiverName: '',
                selfCheckDate: null,
                selfCheckResult: '',
                fileInfo: []
            },
            rules: {
                selfCheckDate: { required: true, message: '自检时间不能为空', trigger: 'change' },
                selfCheckResult: { required: true, message: '处理情况和自检结果不能为空', trigger: 'blur' }
                // fileList:{required: true, message: '整改照片不能为空', trigger: 'change'},
            }
        }
    },
    watch: {
        //这里特殊处理，因为一开进来可能就是第三步或者第二步，如果在mounted或者created里面处理的话，row.id会没有值
        'row.id'() {
            this.getEditInfo()
            this.isSubmit = true
        }
    },
    mounted() {
        if (this.row.id) {
            this.getEditInfo()
            this.isSubmit = true
        }
        this.$bus.$on('rectificationResultsCheckStepOver', () => {
            this.temporaryStorage(true)
        })
    },
    methods: {
        // 获取编辑回显数据
        getEditInfo() {
            this.formData.receiverName = this.row.receiverName
            this.formData.selfCheckDate = this.row.selfCheckDate
            this.formData.selfCheckResult = this.row.selfCheckResult
            // { fileId: '4C7C6900BE35793498AA190C42F44EDD', fileName: '', id: '' }
            this.row.fileList.map(v => {
                this.formData.fileInfo.push({ fileId: v, fileName: v, id: v })
                // this.formData.fileInfo.push({ fileId: '015A64DDFE1A731345800A84A2D8E710', fileName: 'v', commonId: 'v', id: 'v' })
            })
            // this.formData.fileList = ['015A64DDFE1A731345800A84A2D8E710']
            this.$console(this.formData)
            // this.formData = this.row
        },
        temporaryStorage(isNotify) {
            this.$refs.ruleForm.validate((valid, object) => {
                if (valid) {
                    this.formData.id = this.row.id
                    this.loading = true
                    rectificationResultEdit(this.formData).then(res => {
                        if (res.code === 200) {
                            this.$message.success('保存成功')
                            this.isSubmit = true
                            if (isNotify) {
                                this.$bus.$emit('handelApprovalCopy')
                            }
                        }
                        this.loading = false
                    })
                } else {
                    this.$noticeWarning('请填写完整')
                    return false
                }
            })
        }
    }
}
</script>